package com.ninetaildemonfox.zdl.socialproject.config;

import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.google.gson.JsonObject;
import com.hyphenate.chat.EMClient;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.WaitDialog;
import com.ninetaildemonfox.zdl.ninetaildemonfox.base.BaseApplication;
import com.ninetaildemonfox.zdl.ninetaildemonfox.utils.AppManager;
import com.ninetaildemonfox.zdl.socialproject.SpApplication;
import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity.LoginActivity;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;
import com.orhanobut.logger.Logger;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import retrofit2.Response;

/**
 * Author：xiaohaibin
 * Time：2017/9/16
 * Emil：xhb_199409@163.com
 * Github：https://github.com/xiaohaibin/
 * Describe：Constants
 */

public class Constants {
    /**
     * 服务器返回成功正确状态码
     */
    public static final String SERVER_SUCCESS = "1";

    public static final int SERVER_FAILED = 0;

    public static final String SERVER_INVALID = "-1";

    public static final String APPID = "1105172050";

    public static final String SplashPosID = "4080314488610390";

    public static final String NativePosID = "4010024710499065";


    public static Map<String, String> codeGet(AppCompatActivity me, Response<JsonObject> response) {
        if (response == null) {
            return null;
        }
        WaitDialog.dismiss();
        String string = String.valueOf(response.body());
        Logger.json(string);
        Map<String, String> map = JSONUtils.parseKeyAndValueToMap(string);
        if (map == null) {
            return null;
        }
        if (map.get("code").equals(Constants.SERVER_SUCCESS)) {
            return map;
        } else if (map.get("code").equals(Constants.SERVER_INVALID)) {
            //立即开通
            BaseActivity.alerDialog.show();
//            View inflate = SpApplication.appContext.getLayoutInflater().inflate(com.ninetaildemonfox.zdl.ninetaildemonfox.R.layout.dialog, null, false);
            return null;
        } else {
            ToastUtil.show(map.get("message"));
            return null;
        }
    }

    /**
     * 将时间戳转换为时间
     */
    public static String stampDate(long timeMillis) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = new Date(timeMillis);
        return simpleDateFormat.format(date);
    }
}